cd
use "final_using_data.dta", clear

***********Table 1 Descriptive Analysis
estpost tabstat NGO_projects gov_project UN_Agreement socialism GDP_per_capital Bilateral_Trade polity distance English_Language, c(stat) stat(sum mean sd min max n)
esttab using C:\Users\LENOVO\Desktop\descriptive.rtf, cells( "count mean(fmt(%13.2fc)) sd(fmt(%13.2fc)) min(fmt(%13.2fc)) max(fmt(%13.2fc)) ") nonumber nomtitle nonote noobs label collabels( "N" "Mean" "SD" "Min" "Max" ) replace

************Table 2 correlations
estpost correlate NGO_projects gov_project UN_Agreement socialism GDP_per_capital Bilateral_Trade polity distance English_Language , matrix
estimates store corr
esttab corr using C:\Users\LENOVO\Desktop\corr.rtf, replace unstack not noobs compress

************Table 3 Regression Results for NGO Projects
**L1**
global cv "UN_Agreement socialism GDP_per_capital  Bilateral_Trade polity distance English_Language"
global fecv "UN_Agreement GDP_per_capital  Bilateral_Trade polity "
encode Country, gen(country_id)
sort country_id Year
duplicates report country_id Year
duplicates drop country_id Year, force
xtset country_id Year
xtpoisson NGO_projects L1.gov_project $cv, pa vce(robust)
estimates store pa_ppml_1
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L1.gov_project  $cv fit2, pa vce(robust)
test fit2 = 0
drop fit* 
xtpoisson NGO_projects L1.gov_project  $fecv , fe vce(robust)
estimates store fe_ppml_2
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L1.gov_project $fecv fit2, fe vce(robust)
test fit2 = 0
drop fit*			
estimates restore fe_ppml_2
estat ic
**L3** 
xtpoisson NGO_projects L3.gov_project $cv, pa vce(robust)
estimates store pa_ppml_3
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L3.gov_project $cv fit2, pa vce(robust)
test fit2 = 0
drop fit*		
xtpoisson NGO_projects L3.gov_project  $fecv , fe vce(robust)
estimates store fe_ppml_4
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L3.gov_project $fecv fit2, fe vce(robust)
test fit2 = 0
drop fit*			
estimates restore fe_ppml_4
estat ic  
**L5**
xtpoisson NGO_projects L5.gov_project $cv, pa vce(robust)
estimates store pa_ppml_5
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L5.gov_project $cv fit2, pa vce(robust)
test fit2 = 0
drop fit*					
xtpoisson NGO_projects L5.gov_project $fecv, fe vce(robust)
estimates store fe_ppml_6
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L5.gov_project $fecv fit2, fe vce(robust)
test fit2 = 0
drop fit*			
estimates restore fe_ppml_6
estat ic  
esttab pa_ppml_1 fe_ppml_2 pa_ppml_3 fe_ppml_4 pa_ppml_5 fe_ppml_6 using C:\Users\LENOVO\Desktop\mainreg.rtf, append title(Poisson estimation) b(3) se(3) scalars(N chi2) nogaps starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001)

*************Table 4 Estimation Results from More Years of Lags
xtpoisson NGO_projects L6.gov_project $cv, pa vce(robust)
xtpoisson NGO_projects L6.gov_project $fecv , fe vce(robust)
xtpoisson NGO_projects L7.gov_project $cv, pa vce(robust)
xtpoisson NGO_projects L7.gov_project $fecv, fe vce(robust)
xtpoisson NGO_projects L8.gov_project $cv, pa vce(robust)
xtpoisson NGO_projects L8.gov_project $fecv , fe vce(robust)
xtpoisson NGO_projects L9.gov_project $cv, pa vce(robust)
xtpoisson NGO_projects L9.gov_project $fecv , fe vce(robust)



*************************************************Appendices
*************Appendix2 Results from Replacing government projects with government lending
xtpoisson NGO_projects L1.lending_capita_thou $cv, pa vce(robust)
estimates store pa_ppml_1
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L1.lending_capita_thou $cv fit2, pa vce(robust)
test fit2 = 0
drop fit*
xtpoisson NGO_projects L1.lending_capita_thou $fecv, fe vce(robust)
estimates store fe_ppml_2
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L1.lending_capita_thou $fecv fit2, fe vce(robust)
test fit2 = 0
drop fit*
estimates restore fe_ppml_2
estat ic 
xtpoisson NGO_projects L3.lending_capita_thou $cv, pa vce(robust)
estimates store pa_ppml_3
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L3.lending_capita_thou $cv fit2, pa vce(robust)
test fit2 = 0
drop fit*		
xtpoisson NGO_projects L3.lending_capita_thou $fecv, fe vce(robust)
estimates store fe_ppml_4
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L3.lending_capita_thou $fecv fit2, fe vce(robust)
test fit2 = 0
drop fit*
estimates restore fe_ppml_4
estat ic  
xtpoisson NGO_projects L5.lending_capita_thou $cv, pa vce(robust)
estimates store pa_ppml_5
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L5.lending_capita_thou $cv fit2, pa vce(robust)
test fit2 = 0
drop fit*		
xtpoisson NGO_projects L5.lending_capita_thou $fecv , fe vce(robust)
estimates store fe_ppml_6
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L5.lending_capita_thou $fecv fit2, fe vce(robust)
			test fit2 = 0
			drop fit*
estimates restore fe_ppml_6
estat ic  
esttab pa_ppml_1 fe_ppml_2 pa_ppml_3 fe_ppml_4 pa_ppml_5 fe_ppml_6  using C:\Users\LENOVO\Desktop\Appendix2.rtf, append title(Poisson estimation) b(3) se(3) scalars(N chi2) nogaps starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001)  

*************Appendix3 Results from Replacing AidData V3 with AidData V1****created a new dataset with Aiddata V1 and rerun the analysis**** 
*Population weighted 

xtpoisson NGO_projects L5.gov_project_year_agg L5.lending_capita_thou polity2 CHN_agree_agg socialism bil_trade_bil dist_thou cgdp_thou eng_lang, pa vce(robust)
estimates store pa_ppml_1
* RESET Test to test for functional misspecification
		predict fit, xb
			generate fit2 = fit^2
		    xtpoisson NGO_projects L5.gov_project_year_agg L5.lending_capita_thou  polity2 CHN_agree_agg socialism bil_trade_bil dist_thou  cgdp_thou eng_lang fit2, pa vce(robust)
			test fit2 = 0
			drop fit*

*Fixed effects 

xtpoisson NGO_projects L5.gov_project_year_agg L5.lending_capita_thou  polity2 CHN_agree_agg socialism bil_trade_bil cgdp_thou , fe vce(robust)
estimates store fe_ppml_2
* RESET Test to test for functional misspecification
		predict fit, xb
			generate fit2 = fit^2
		    xtpoisson NGO_projects L5.gov_project_year_agg L5.lending_capita_thou  polity2 CHN_agree_agg socialism bil_trade_bil cgdp_thou fit2, fe vce(robust)
			test fit2 = 0
			drop fit*
			
* Information criterion
estimates restore fe_ppml_2
estat ic 

*Population weighted 

xtpoisson NGO_projects L3.gov_project_year_agg L3.lending_capita_thou  polity2  CHN_agree_agg socialism bil_trade_bil dist_thou  cgdp_thou  eng_lang , pa vce(robust)
estimates store pa_ppml_3
* RESET Test to test for functional misspecification
		predict fit, xb
			generate fit2 = fit^2
		    xtpoisson NGO_projects L3.gov_project_year_agg L3.lending_capita_thou  polity2 CHN_agree_agg socialism bil_trade_bil dist_thou  cgdp_thou eng_lang fit2, pa vce(robust)
			test fit2 = 0
			drop fit*

* Fixed effects 
			
xtpoisson NGO_projects L3.gov_project_year_agg L3.lending_capita_thou  polity2 CHN_agree_agg socialism bil_trade_bil cgdp_thou , fe vce(robust)
estimates store fe_ppml_4


* RESET Test to test for functional misspecification
		predict fit, xb
			generate fit2 = fit^2
		    xtpoisson NGO_projects L3.gov_project_year_agg L3.lending_capita_thou  polity2 CHN_agree_agg socialism bil_trade_bil cgdp_thou  fit2, fe vce(robust)
			test fit2 = 0
			drop fit*
			
*Information criteria 
estimates restore fe_ppml_4
estat ic  

*Population weighted 

xtpoisson NGO_projects L1.gov_project_year_agg L1.lending_capita_thou polity2 CHN_agree_agg socialism bil_trade_bil dist_thou  cgdp_thou eng_lang, pa vce(robust)
estimates store pa_ppml_5
* RESET Test to test for functional misspecification
		predict fit, xb
			generate fit2 = fit^2
		    xtpoisson NGO_projects L1.gov_project_year_agg L1.lending_capita_thou  polity2 CHN_agree_agg socialism bil_trade_bil dist_thou  cgdp_thou eng_lang fit2, pa vce(robust)
			test fit2 = 0
			drop fit*
			
* Fixed effects 
			
xtpoisson NGO_projects L1.gov_project_year_agg L1.lending_capita_thou  polity2 CHN_agree_agg socialism bil_trade_bil cgdp_thou , fe vce(robust)
estimates store fe_ppml_6

* RESET Test to test for functional misspecification
		predict fit, xb
			generate fit2 = fit^2
		    xtpoisson NGO_projects L1.gov_project_year_agg L1.lending_capita_thou polity2 CHN_agree_agg socialism bil_trade_bil cgdp_thou  fit2, fe vce(robust)
			test fit2 = 0
			drop fit*
			
* Information criteria 
estimates restore fe_ppml_6
estat ic  


* Export estimates in text format
esttab pa_ppml_1 fe_ppml_2 pa_ppml_3 fe_ppml_4 pa_ppml_5 fe_ppml_6 using "output/regression output pa_fe_ppml.tex", append title(Poisson estimation) b(3) se(3) scalars(N chi2) nogaps starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001)  



*************Appendix4: Results from Replacing Polity with Polyarchy 
global cv1 "UN_Agreement socialism GDP_per_capital  Bilateral_Trade Polyarchy distance English_Language"
global fecv1 "UN_Agreement GDP_per_capital  Bilateral_Trade Polyarchy "
**L1
xtpoisson NGO_projects L1.gov_project $cv1, pa vce(robust)
estimates store pa_ppml_1
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L1.gov_project  $cv1 fit2, pa vce(robust)
test fit2 = 0
drop fit* 
xtpoisson NGO_projects L1.gov_project  $fecv1 , fe vce(robust)
estimates store fe_ppml_2
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L1.gov_project $fecv1 fit2, fe vce(robust)
test fit2 = 0
drop fit*			
estimates restore fe_ppml_2
estat ic
**L3** 
xtpoisson NGO_projects L3.gov_project $cv1, pa vce(robust)
estimates store pa_ppml_3
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L3.gov_project $cv1 fit2, pa vce(robust)
test fit2 = 0
drop fit*		
xtpoisson NGO_projects L3.gov_project  $fecv1 , fe vce(robust)
estimates store fe_ppml_4
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L3.gov_project $fecv1 fit2, fe vce(robust)
test fit2 = 0
drop fit*			
estimates restore fe_ppml_4
estat ic  
**L5**
xtpoisson NGO_projects L5.gov_project $cv1, pa vce(robust)
estimates store pa_ppml_5
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L5.gov_project $cv1 fit2, pa vce(robust)
test fit2 = 0
drop fit*					
xtpoisson NGO_projects L5.gov_project $fecv1, fe vce(robust)
estimates store fe_ppml_6
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L5.gov_project $fecv1 fit2, fe vce(robust)
test fit2 = 0
drop fit*			
estimates restore fe_ppml_6
estat ic  
esttab pa_ppml_1 fe_ppml_2 pa_ppml_3 fe_ppml_4 pa_ppml_5 fe_ppml_6 using C:\Users\LENOVO\Desktop\Appendix4.rtf, append title(Poisson estimation) b(3) se(3) scalars(N chi2) nogaps starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001)

*************Appendix5: Results from Replacing GDP per capita with HDI
global cv2 "UN_Agreement socialism HDI  Bilateral_Trade polity distance English_Language"
global fecv2 "UN_Agreement HDI  Bilateral_Trade polity "
**L1
xtpoisson NGO_projects L1.gov_project $cv2, pa vce(robust)
estimates store pa_ppml_1
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L1.gov_project  $cv2 fit2, pa vce(robust)
test fit2 = 0
drop fit* 
xtpoisson NGO_projects L1.gov_project  $fecv2 , fe vce(robust)
estimates store fe_ppml_2
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L1.gov_project $fecv2 fit2, fe vce(robust)
test fit2 = 0
drop fit*			
estimates restore fe_ppml_2
estat ic
**L3** 
xtpoisson NGO_projects L3.gov_project $cv2, pa vce(robust)
estimates store pa_ppml_3
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L3.gov_project $cv2 fit2, pa vce(robust)
test fit2 = 0
drop fit*		
xtpoisson NGO_projects L3.gov_project  $fecv2 , fe vce(robust)
estimates store fe_ppml_4
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L3.gov_project $fecv2 fit2, fe vce(robust)
test fit2 = 0
drop fit*			
estimates restore fe_ppml_4
estat ic  
**L5**
xtpoisson NGO_projects L5.gov_project $cv2, pa vce(robust)
estimates store pa_ppml_5
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L5.gov_project $cv2 fit2, pa vce(robust)
test fit2 = 0
drop fit*					
xtpoisson NGO_projects L5.gov_project $fecv2, fe vce(robust)
estimates store fe_ppml_6
predict fit, xb
generate fit2 = fit^2
xtpoisson NGO_projects L5.gov_project $fecv2 fit2, fe vce(robust)
test fit2 = 0
drop fit*			
estimates restore fe_ppml_6
estat ic  
esttab pa_ppml_1 fe_ppml_2 pa_ppml_3 fe_ppml_4 pa_ppml_5 fe_ppml_6 using C:\Users\LENOVO\Desktop\Appendix5.rtf, append title(Poisson estimation) b(3) se(3) scalars(N chi2) nogaps starlevels(+ 0.10 * 0.05 ** 0.01 *** 0.001)